package com.yunduo.world.utils;

import com.google.protobuf.ByteString;
import com.yunduo.world.entity.EntityInfo;

/**
 * 生成实体对象
 */
public class EntityBuild {

    /**
     * 响应数据
     * @param header 响应头，决定处理器
     * @param context 响应体，决定具体处理方法
     * @param status 响应状态
     * @param bytes 响应数据
     * @return
     */
    public static EntityInfo.Entity buildMessage(String header,String context,boolean status,byte[] bytes){
        EntityInfo.Entity msg = EntityInfo.Entity.newBuilder()
                .setOperation(header)
                .setDataType(EntityInfo.Entity.EntityType.MessageType)
                .setMsg(EntityInfo.Message.newBuilder().setContext(context).setData(ByteString.copyFrom(bytes)).setStatus(status).build())
                .build();
        return msg;
    }
    public static EntityInfo.Entity buildMessage(String header,String context,boolean status,ByteString bytes){
        EntityInfo.Entity msg = EntityInfo.Entity.newBuilder()
                .setOperation(header)
                .setDataType(EntityInfo.Entity.EntityType.MessageType)
                .setMsg(EntityInfo.Message.newBuilder().setContext(context).setData(bytes).setStatus(status).build())
                .build();
        return msg;
    }

    public static EntityInfo.Entity buildMessage(String header,String context,boolean status){
        EntityInfo.Entity msg = EntityInfo.Entity.newBuilder()
                .setOperation(header)
                .setDataType(EntityInfo.Entity.EntityType.MessageType)
                .setMsg(EntityInfo.Message.newBuilder().setContext(context).setStatus(status).build())
                .build();
        return msg;
    }
}
